using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class BaoCaoDoanhThuDAO
    {
        public BaoCaoDoanhThuDTO[] LapBaoCaoDoanhThu(int Thang)
        {
            BaoCaoDoanhThuDTO[] Arr = new BaoCaoDoanhThuDTO[100];
            try
            {
                int year = DateTime.Now.Year;
                DateTime ThangBD = new DateTime(year, Thang, 1);
                DateTime ThangKT = new DateTime(year, Thang + 1, 1);
                DataTable dt = new DataTable();
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_BaoCaoDoanhThu";

                cmd.Parameters.Add("@ThangBD", SqlDbType.DateTime);
                cmd.Parameters.Add("@ThangKT", SqlDbType.DateTime);

                cmd.Parameters["@ThangBD"].Value = ThangBD;
                cmd.Parameters["@ThangKT"].Value = ThangKT;

                cmd.ExecuteNonQuery();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);

                int count = dt.Rows.Count;
                Arr = new BaoCaoDoanhThuDTO[count];
                for (int i = 0; i < count; i++)
                {
                    Arr[i] = new BaoCaoDoanhThuDTO();
                    Arr[i].MaLoaiPhong = dt.Rows[i]["MaLP"].ToString();
                    Arr[i].TenLoaiPhong = dt.Rows[i]["TenLP"].ToString();
                    Arr[i].DoanhThu = Convert.ToDouble(dt.Rows[i]["DoanhThu"].ToString());
                }


                con.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return Arr;
        }
    }
}
